﻿package org.uranus.mainGUI;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;
import org.uranus.core.dataHandler.HostInfoData;
import org.uranus.core.dataHandler.HostListRMS;
import org.uranus.core.dataHandler.RMS;

import org.uranus.core.terminal.Terminal;

/**
 *
 * @author Koi Chan
 */
public class GUI extends MIDlet implements CommandListener {
    
    /**
     * Creates a new instance of GUI
     */
    public GUI() {
        terminal = get_Terminal();      
        
        initialize();
    }
    
    /** Note: about alg mark comment,  n := hosts list stored in RMS database.
     *                                 m := Entire RMD database data, where m > n.
     *
     *        purpose: To prevent un-efficienlly used of RMS databse.
     */
    
    private List rootSelScrn;//GEN-BEGIN:MVDFields
    private Command rootSelScrnExitCmd;
    private Command okCommand7;
    private Form sshLogin;
    private TextField sshLogin_idTF;
    private TextField sshLogin_pwdTF;
    private Form aboutForm;
    private StringItem AboutString;
    private Form helpForm;
    private StringItem HelpString;
    private Command backToRootCmd;
    private ChoiceGroup c2hi_protocolSel;
    private Form ConnectToHostInput;
    private Spacer spacer1;
    private TextField c2hi_hostTF;
    private TextField c2hi_hostPortTF;
    private Command sshLogin_backCmd;
    private TextField c2hi_aliasTF;//GEN-END:MVDFields
    private Command hostList_newCmd;
    private Command hostList_editCmd;
    private Command hostList_delCmd;
    
    public static Terminal terminal;
    private List hostList;
    private List xhostList;
    private HostInfoData hostInfo;
    private HostListRMS hostListRecord;
    
    private boolean isEditing;
    private boolean modified;
//GEN-LINE:MVDMethods
    
    /** Called by the system to indicate that a command has been invoked on a particular displayable.//GEN-BEGIN:MVDCABegin
     * @param command the Command that ws invoked
     * @param displayable the Displayable on which the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:MVDCABegin
        // Insert global pre-action code here
        if (displayable == rootSelScrn) {//GEN-BEGIN:MVDCABody
            if (command == rootSelScrn.SELECT_COMMAND) {
                switch (get_rootSelScrn().getSelectedIndex()) {
                    case 0://GEN-END:MVDCABody
                        /*
getDisplay ().setCurrent (get_ConnectToHostInput());//GEN-LINE:MVDCAAction5
                         */
                        getDisplay().setCurrent(get_hostList());
                        break;//GEN-BEGIN:MVDCACase5
                    case 1://GEN-END:MVDCACase5
                        // Insert pre-action code here
                        getDisplay().setCurrent(get_helpForm());//GEN-LINE:MVDCAAction197
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase197
                    case 2://GEN-END:MVDCACase197
                        // Insert pre-action code here
                        getDisplay().setCurrent(get_aboutForm());//GEN-LINE:MVDCAAction199
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase199
                    case 3://GEN-END:MVDCACase199
                        // Insert pre-action code here
                        exitMIDlet();//GEN-LINE:MVDCAAction201
                        // Insert post-action code here
                        break;//GEN-BEGIN:MVDCACase201
                }
            } else if (command == rootSelScrnExitCmd) {//GEN-END:MVDCACase201
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:MVDCAAction9
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase9
        } else if (displayable == ConnectToHostInput) {
            if (command == okCommand7) {//GEN-END:MVDCACase9
                if(get_c2hi_aliasTF().getString().length() == 0){
                    getDisplay().setCurrent(new Alert("站台名稱不得為空","請輸入站台名稱",null,AlertType.ERROR));
                }else if(get_c2hi_hostTF().getString().length() == 0){
                    getDisplay().setCurrent(new Alert("站台位址不得為空","請輸入站台位址",null,AlertType.ERROR));
                }else if(isEditing){
                    String temp = (get_c2hi_hostPortTF().getString().length() > 0)? get_c2hi_hostPortTF().getString() :
                        ((get_c2hi_protocolSel().getSelectedIndex() == 0)? "23" : "22");
                    get_c2hi_hostPortTF().setString(temp);
                    
                    if( get_c2hi_protocolSel().isSelected(0)){
                        hostInfo = new HostInfoData(
                                get_c2hi_aliasTF().getString(),
                                get_c2hi_hostTF().getString(),
                                "TELNET",
                                Integer.parseInt(get_c2hi_hostPortTF().getString()),
                                "",
                                "");
                        
                        isEditing = false;
                        getDisplay().setCurrent(get_hostList());
                    }
                    else if(get_c2hi_protocolSel().isSelected(1)){
                        getDisplay().setCurrent(get_sshLogin());
                    }
                    
                }else {
                    
                    String[] list = get_hostListRecord().getList();   // alg mark: loop n times. ( excluding constructor m times)
                    for(int i = 0 ; i < list.length ; i++){
                        if(list[i].equals(get_c2hi_aliasTF().getString())){
                            getDisplay().setCurrent(new Alert("此站台已存在!","此名稱之站台已存在, 請改使用其他名稱",null, AlertType.ERROR));
                            return;
                        }
                    }    // alg mark: loop n + n times
                    
                    String temp = (get_c2hi_hostPortTF().getString().length() > 0)? get_c2hi_hostPortTF().getString() :
                        ((get_c2hi_protocolSel().getSelectedIndex() == 0)? "23" : "22");
                    get_c2hi_hostPortTF().setString(temp);
                    if( get_c2hi_protocolSel().isSelected(0)){
                        hostInfo = new HostInfoData(
                                get_c2hi_aliasTF().getString(),
                                get_c2hi_hostTF().getString(),
                                "TELNET",
                                Integer.parseInt(get_c2hi_hostPortTF().getString()),
                                "",
                                "");
                        get_hostListRecord().addRecord(get_c2hi_aliasTF().getString());
                        getDisplay().setCurrent(get_hostList());
                    }else if( get_c2hi_protocolSel().isSelected(1)){
                        getDisplay().setCurrent(get_sshLogin());
                    }
                }
                // Do nothing//GEN-LINE:MVDCAAction152
                // Insert post-action code here
            } else if (command == rootSelScrnExitCmd) {//GEN-LINE:MVDCACase152
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:MVDCAAction148
                // Insert post-action code here
            } else if (command == backToRootCmd) {//GEN-LINE:MVDCACase148
                // Insert pre-action code here
                getDisplay().setCurrent(get_rootSelScrn());//GEN-LINE:MVDCAAction150
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase150
        } else if (displayable == aboutForm) {
            if (command == backToRootCmd) {//GEN-END:MVDCACase150
                // Insert pre-action code here
                getDisplay().setCurrent(get_rootSelScrn());//GEN-LINE:MVDCAAction215
                // Insert post-action code here
            } else if (command == rootSelScrnExitCmd) {//GEN-LINE:MVDCACase215
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:MVDCAAction213
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase213
        } else if (displayable == helpForm) {
            if (command == rootSelScrnExitCmd) {//GEN-END:MVDCACase213
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:MVDCAAction209
                // Insert post-action code here
            } else if (command == backToRootCmd) {//GEN-LINE:MVDCACase209
                // Insert pre-action code here
                getDisplay().setCurrent(get_rootSelScrn());//GEN-LINE:MVDCAAction211
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase211
        } else if (displayable == sshLogin) {
            if (command == okCommand7) {//GEN-END:MVDCACase211
                //String hostName, String address, String protocol, int port, String id,String pwd
                if(get_sshLogin_idTF().getString().length() == 0){
                    getDisplay().setCurrent(new Alert("ID欄位不得空白","請輸入id",null, AlertType.ERROR));
                }else if(get_sshLogin_pwdTF().getString().length() == 0){
                    getDisplay().setCurrent(new Alert("Password欄位不得空白", "請輸入password", null, AlertType.ERROR));
                }else{
                    hostInfo = new HostInfoData(
                            get_c2hi_aliasTF().getString(),
                            get_c2hi_hostTF().getString(),
                            "SSH",
                            Integer.parseInt(get_c2hi_hostPortTF().getString()),
                            get_sshLogin_idTF().getString(),
                            get_sshLogin_pwdTF().getString());
                    
                    if( !isEditing ){
                        get_hostListRecord().addRecord(get_c2hi_aliasTF().getString());
                    }                    
                    isEditing = false;
                    getDisplay().setCurrent(get_hostList());
                }
                // Do nothing//GEN-LINE:MVDCAAction237
                // Insert post-action code here
            } else if (command == sshLogin_backCmd) {//GEN-LINE:MVDCACase237
                // Insert pre-action code here
                getDisplay().setCurrent(get_ConnectToHostInput());//GEN-LINE:MVDCAAction233
                // Insert post-action code here
            }//GEN-BEGIN:MVDCACase233
        }//GEN-END:MVDCACase233
else if(displayable == hostList){
            if(command == hostList_newCmd){
                modified = true;
                isEditing = false;
                getDisplay().setCurrent(get_ConnectToHostInput());
            }else if( command == hostList_delCmd){
                if(!get_hostListRecord().findRecord("Hosts_list")){
                    return;
                }
                get_hostListRecord().delRecord(get_hostList().getString(get_hostList().getSelectedIndex()));
                modified = true;
                
                getDisplay().setCurrent(get_hostList());
            }else if( command == okCommand7){
                if( get_hostList().getSelectedIndex() >= 0 ){
                    hostInfo = get_hostListRecord().getSelectedHost(get_hostList().getSelectedIndex());
                    start_session(hostInfo);
                }
            } else if( command == get_hostList_editCmd()){
                showDB();
                if( get_hostList().getSelectedIndex() >= 0){
                    hostInfo = get_hostListRecord().getSelectedHost(get_hostList().getSelectedIndex());
                    isEditing = true;
                    getDisplay().setCurrent(get_ConnectToHostInput());
                }
            }
            
            
            
}
}//GEN-LINE:MVDCAEnd
    
    /** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin
     */
    private void initialize() {//GEN-END:MVDInitBegin
        modified = false;
        isEditing = false;
        getDisplay().setCurrent(get_rootSelScrn());//GEN-LINE:MVDInitInit
        
    }//GEN-LINE:MVDInitEnd
    
    
    /**
     * This method should return an instance of the display.
     */
    public Display getDisplay() {//GEN-FIRST:MVDGetDisplay
        return Display.getDisplay(this);
    }//GEN-LAST:MVDGetDisplay
    
    /**
     * This method should exit the midlet.
     */
    public void exitMIDlet() {//GEN-FIRST:MVDExitMidlet
        getDisplay().setCurrent(null);
        destroyApp(true);
        notifyDestroyed();
    }//GEN-LAST:MVDExitMidlet
    
    /** This method returns instance for rootSelScrn component and should be called instead of accessing rootSelScrn field directly.//GEN-BEGIN:MVDGetBegin2
     * @return Instance for rootSelScrn component
     */
    public List get_rootSelScrn() {
        if (rootSelScrn == null) {//GEN-END:MVDGetBegin2
            // Insert pre-init code here
            rootSelScrn = new List(null, Choice.IMPLICIT, new String[] {//GEN-BEGIN:MVDGetInit2
                "\u9060\u7AEF\u9023\u7DDA",
                "\u5E6B\u52A9",
                "\u95DC\u65BC",
                "\u9000\u51FA"
            }, new Image[] {
                null,
                null,
                null,
                null
            });
            rootSelScrn.addCommand(get_rootSelScrnExitCmd());
            rootSelScrn.setCommandListener(this);
            rootSelScrn.setSelectedFlags(new boolean[] {
                false,
                false,
                false,
                false
            });//GEN-END:MVDGetInit2
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd2
        return rootSelScrn;
    }//GEN-END:MVDGetEnd2
    /**
     * private List get_delList(){
     * String[] list = get_hostListRecord().getList();
     *
     * }**/
    public List get_hostList(){
        if( hostList == null || modified){
            String[] list = get_hostListRecord().getList(); // GET user data through RMS
            hostList = new List(null, Choice.IMPLICIT, list, null);
            
            hostList.addCommand(get_hostList_newCmd());
            hostList.addCommand(get_hostList_editCmd());
            hostList.addCommand(get_hostList_delCmd());
            hostList.addCommand(get_okCommand7());
            hostList.addCommand(this.get_backToRootCmd());
            hostList.setCommandListener(this);
            
            modified = false;
        }
        return hostList;
    }
    
    
    private void showDB(){
        String[] list = RecordStore.listRecordStores();
        if(list == null){
            System.out.println("null");
            return;
        }
        for(int i = 0 ; i < list.length ; i++){
            System.out.println(list[i]);
        }
    }
    
    private HostListRMS get_hostListRecord(){
        return new HostListRMS();
    }
    
    public Command get_hostList_newCmd(){
        if(hostList_newCmd == null){
            hostList_newCmd = new Command("新增",Command.OK,1);
            
        }
        return hostList_newCmd;
    }
    
    public Command get_hostList_editCmd(){
        if(hostList_editCmd == null){
            hostList_editCmd = new Command("編輯",Command.OK,1);
        }
        return hostList_editCmd;
    }
    
    public Command get_hostList_delCmd(){
        if(hostList_delCmd == null){
            hostList_delCmd = new Command("刪除",Command.OK,1);
        }
        return hostList_delCmd;
    }
    
    /** This method returns instance for rootSelScrnExitCmd component and should be called instead of accessing rootSelScrnExitCmd field directly.//GEN-BEGIN:MVDGetBegin8
     * @return Instance for rootSelScrnExitCmd component
     */
    public Command get_rootSelScrnExitCmd() {
        if (rootSelScrnExitCmd == null) {//GEN-END:MVDGetBegin8
            // Insert pre-init code here
            rootSelScrnExitCmd = new Command("Exit", Command.EXIT, 1);//GEN-LINE:MVDGetInit8
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd8
        return rootSelScrnExitCmd;
    }//GEN-END:MVDGetEnd8
    
    
    /** This method returns instance for c2hi_hostTF component and should be called instead of accessing c2hi_hostTF field directly.//GEN-BEGIN:MVDGetBegin137
     * @return Instance for c2hi_hostTF component
     */
    public TextField get_c2hi_hostTF() {
        if (c2hi_hostTF == null) {//GEN-END:MVDGetBegin137
            // Insert pre-init code here
            c2hi_hostTF = new TextField("Host", "", 120, TextField.ANY);//GEN-LINE:MVDGetInit137
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd137
        return c2hi_hostTF;
    }//GEN-END:MVDGetEnd137
            /** This method returns instance for spacer1 component and should be called instead of accessing spacer1 field directly.//GEN-BEGIN:MVDGetBegin139
     * @return Instance for spacer1 component
     */
    public Spacer get_spacer1() {
        if (spacer1 == null) {//GEN-END:MVDGetBegin139
            // Insert pre-init code here
            spacer1 = new Spacer(1000, 1);//GEN-LINE:MVDGetInit139
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd139
        return spacer1;
    }//GEN-END:MVDGetEnd139
  
    
    /** This method returns instance for okCommand7 component and should be called instead of accessing okCommand7 field directly.//GEN-BEGIN:MVDGetBegin151
     * @return Instance for okCommand7 component
     */
    public Command get_okCommand7() {
        if (okCommand7 == null) {//GEN-END:MVDGetBegin151
            // Insert pre-init code here
            okCommand7 = new Command("\u78BA\u5B9A", Command.OK, 0);//GEN-LINE:MVDGetInit151
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd151
        return okCommand7;
    }//GEN-END:MVDGetEnd151
   
    
    /** This method returns instance for sshLogin component and should be called instead of accessing sshLogin field directly.//GEN-BEGIN:MVDGetBegin175
     * @return Instance for sshLogin component
     */
    public Form get_sshLogin() {
        if (sshLogin == null) {//GEN-END:MVDGetBegin175
            // Insert pre-init code here
            sshLogin = new Form(null, new Item[] {//GEN-BEGIN:MVDGetInit175
                get_sshLogin_idTF(),
                get_sshLogin_pwdTF()
            });
            sshLogin.addCommand(get_sshLogin_backCmd());
            sshLogin.addCommand(get_okCommand7());
            sshLogin.setCommandListener(this);//GEN-END:MVDGetInit175
            
        }//GEN-BEGIN:MVDGetEnd175
	
        if( isEditing ){
            get_sshLogin_idTF().setString(hostInfo.getId());
            get_sshLogin_pwdTF().setString(hostInfo.getPwd());
        }
        return sshLogin;
        
    }//GEN-END:MVDGetEnd175
    
    /** This method returns instance for sshLogin_idTF component and should be called instead of accessing sshLogin_idTF field directly.//GEN-BEGIN:MVDGetBegin176
     * @return Instance for sshLogin_idTF component
     */
    public TextField get_sshLogin_idTF() {
        if (sshLogin_idTF == null) {//GEN-END:MVDGetBegin176
            // Insert pre-init code here
            sshLogin_idTF = new TextField("ID", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit176
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd176
        return sshLogin_idTF;
    }//GEN-END:MVDGetEnd176
    
    /** This method returns instance for sshLogin_pwdTF component and should be called instead of accessing sshLogin_pwdTF field directly.//GEN-BEGIN:MVDGetBegin177
     * @return Instance for sshLogin_pwdTF component
     */
    public TextField get_sshLogin_pwdTF() {
        if (sshLogin_pwdTF == null) {//GEN-END:MVDGetBegin177
            // Insert pre-init code here
            sshLogin_pwdTF = new TextField("Password", null, 120, TextField.ANY | TextField.PASSWORD);//GEN-LINE:MVDGetInit177
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd177
        return sshLogin_pwdTF;
    }//GEN-END:MVDGetEnd177
    
    
    /** This method returns instance for c2hi_protocolSel component and should be called instead of accessing c2hi_protocolSel field directly.//GEN-BEGIN:MVDGetBegin193
     * @return Instance for c2hi_protocolSel component
     */
    public ChoiceGroup get_c2hi_protocolSel() {
        if (c2hi_protocolSel == null) {//GEN-END:MVDGetBegin193
            // Insert pre-init code here
            c2hi_protocolSel = new ChoiceGroup("Protocol:", Choice.EXCLUSIVE, new String[] {//GEN-BEGIN:MVDGetInit193
                "Telnet",
                "SSH"
            }, new Image[] {
                null,
                null
            });
            c2hi_protocolSel.setSelectedFlags(new boolean[] {
                false,
                false
            });//GEN-END:MVDGetInit193
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd193
        return c2hi_protocolSel;
    }//GEN-END:MVDGetEnd193
    
    /** This method returns instance for aboutForm component and should be called instead of accessing aboutForm field directly.//GEN-BEGIN:MVDGetBegin202
     * @return Instance for aboutForm component
     */
    public Form get_aboutForm() {
        if (aboutForm == null) {//GEN-END:MVDGetBegin202
            // Insert pre-init code here
            aboutForm = new Form(null, new Item[] {get_AboutString()});//GEN-BEGIN:MVDGetInit202
            aboutForm.addCommand(get_rootSelScrnExitCmd());
            aboutForm.addCommand(get_backToRootCmd());
            aboutForm.setCommandListener(this);//GEN-END:MVDGetInit202
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd202
        return aboutForm;
    }//GEN-END:MVDGetEnd202
    
    /** This method returns instance for AboutString component and should be called instead of accessing AboutString field directly.//GEN-BEGIN:MVDGetBegin203
     * @return Instance for AboutString component
     */
    public StringItem get_AboutString() {
        if (AboutString == null) {//GEN-END:MVDGetBegin203
            // Insert pre-init code here
            AboutString = new StringItem("About", "<Enter Text>");//GEN-LINE:MVDGetInit203
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd203
        return AboutString;
    }//GEN-END:MVDGetEnd203
    
    /** This method returns instance for helpForm component and should be called instead of accessing helpForm field directly.//GEN-BEGIN:MVDGetBegin204
     * @return Instance for helpForm component
     */
    public Form get_helpForm() {
        if (helpForm == null) {//GEN-END:MVDGetBegin204
            // Insert pre-init code here
            helpForm = new Form(null, new Item[] {get_HelpString()});//GEN-BEGIN:MVDGetInit204
            helpForm.addCommand(get_rootSelScrnExitCmd());
            helpForm.addCommand(get_backToRootCmd());
            helpForm.setCommandListener(this);//GEN-END:MVDGetInit204
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd204
        return helpForm;
    }//GEN-END:MVDGetEnd204
    
    /** This method returns instance for HelpString component and should be called instead of accessing HelpString field directly.//GEN-BEGIN:MVDGetBegin205
     * @return Instance for HelpString component
     */
    public StringItem get_HelpString() {
        if (HelpString == null) {//GEN-END:MVDGetBegin205
            // Insert pre-init code here
            HelpString = new StringItem("Help", "<Enter Text>");//GEN-LINE:MVDGetInit205
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd205
        return HelpString;
    }//GEN-END:MVDGetEnd205
    
    /** This method returns instance for backToRootCmd component and should be called instead of accessing backToRootCmd field directly.//GEN-BEGIN:MVDGetBegin210
     * @return Instance for backToRootCmd component
     */
    public Command get_backToRootCmd() {
        if (backToRootCmd == null) {//GEN-END:MVDGetBegin210
            // Insert pre-init code here
            backToRootCmd = new Command("\u4E0A\u4E00\u9801", Command.BACK, 5);//GEN-LINE:MVDGetInit210
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd210
        return backToRootCmd;
    }//GEN-END:MVDGetEnd210
    
    
    /** This method returns instance for c2hi_hostPortTF component and should be called instead of accessing c2hi_hostPortTF field directly.//GEN-BEGIN:MVDGetBegin138
     * @return Instance for c2hi_hostPortTF component
     */
    public TextField get_c2hi_hostPortTF() {
        if (c2hi_hostPortTF == null) {//GEN-END:MVDGetBegin138
            
            c2hi_hostPortTF = new TextField("Port \n(leave blank for default)", "", 10, TextField.NUMERIC);//GEN-LINE:MVDGetInit138
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd138
        return c2hi_hostPortTF;
    }//GEN-END:MVDGetEnd138
    
    /** This method returns instance for ConnectToHostInput component and should be called instead of accessing ConnectToHostInput field directly.//GEN-BEGIN:MVDGetBegin136
     * @return Instance for ConnectToHostInput component
     */
    public Form get_ConnectToHostInput() {
        if (ConnectToHostInput == null) {//GEN-END:MVDGetBegin136
            // Insert pre-init code here
            ConnectToHostInput = new Form(null, new Item[] {//GEN-BEGIN:MVDGetInit136
                get_c2hi_aliasTF(),
                get_c2hi_hostTF(),
                get_spacer1(),
                get_c2hi_protocolSel(),
                get_c2hi_hostPortTF()
            });
            ConnectToHostInput.addCommand(get_rootSelScrnExitCmd());
            ConnectToHostInput.addCommand(get_backToRootCmd());
            ConnectToHostInput.addCommand(get_okCommand7());
            ConnectToHostInput.setCommandListener(this);//GEN-END:MVDGetInit136
            
        }//GEN-BEGIN:MVDGetEnd136
//GEN-END:MVDGetEnd136
        if( isEditing ){
            get_c2hi_aliasTF().setString(hostInfo.getHostName());
            get_c2hi_hostTF().setString(hostInfo.getAddress());
            if( hostInfo.getProtocol().equals("SSH")){
                get_c2hi_protocolSel().setSelectedIndex(1, true);
            }else {
                get_c2hi_protocolSel().setSelectedIndex(0, true);
            }
            get_c2hi_hostPortTF().setString(hostInfo.getPort() + "");
            isEditing = false;
        }else{
            get_c2hi_aliasTF().setString("");
            get_c2hi_hostTF().setString("");
            get_c2hi_hostPortTF().setString("");
        }
        return ConnectToHostInput;
    }
    
    /** This method returns instance for sshLogin_backCmd component and should be called instead of accessing sshLogin_backCmd field directly.//GEN-BEGIN:MVDGetBegin232
     * @return Instance for sshLogin_backCmd component
     */
    public Command get_sshLogin_backCmd() {
        if (sshLogin_backCmd == null) {//GEN-END:MVDGetBegin232
            // Insert pre-init code here
            sshLogin_backCmd = new Command("\u4E0A\u4E00\u9801", Command.BACK, 1);//GEN-LINE:MVDGetInit232
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd232
        return sshLogin_backCmd;
    }//GEN-END:MVDGetEnd232
    
    /** This method returns instance for c2hi_aliasTF component and should be called instead of accessing c2hi_aliasTF field directly.//GEN-BEGIN:MVDGetBegin238
     * @return Instance for c2hi_aliasTF component
     */
    public TextField get_c2hi_aliasTF() {
        if (c2hi_aliasTF == null) {//GEN-END:MVDGetBegin238
            // Insert pre-init code here
            c2hi_aliasTF = new TextField("Alias", null, 120, TextField.ANY);//GEN-LINE:MVDGetInit238
            // Insert post-init code here
        }//GEN-BEGIN:MVDGetEnd238
        return c2hi_aliasTF;
    }//GEN-END:MVDGetEnd238
    
    
    
    private void start_session(HostInfoData hostInfo) throws IllegalArgumentException{
        terminal.setGUI(this);
        terminal.startTerminal(hostInfo);
        getDisplay().setCurrent(terminal);
    }
    
    private Terminal get_Terminal(){
        terminal = (terminal == null)? new Terminal() : terminal;
        return terminal;
    }
    
    public static Terminal getCurrentTerminal(){
        return terminal;
    }    
    
    public void startApp() {
        
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
}
